package org.manusoft.refill.view;

import java.io.Serializable;
import java.util.HashMap;

import javax.faces.event.ActionEvent;

import org.manusoft.refill.domain.MyLazyDataModel;
import org.manusoft.refill.domain.TRefillingDetailsRf;
import org.manusoft.refill.service.AllotmentService;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component("manageMovies")
@Scope("session")
public class ManageMovies implements Serializable {

    private LazyDataModel<TRefillingDetailsRf> lazyDataModel;
    private AllotmentService allotmentService;
    private String title;
    private TRefillingDetailsRf[] selectedMovies;

    @Autowired
    public ManageMovies(AllotmentService allotmentService) {
        this.allotmentService = allotmentService;
        lazyDataModel = new MyLazyDataModel(allotmentService);
    }

    public LazyDataModel<TRefillingDetailsRf> getMovies() {
        return lazyDataModel;
    }

    public void setMovies(LazyDataModel<TRefillingDetailsRf> movies) {
        this.lazyDataModel = movies;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public TRefillingDetailsRf[] getSelectedMovies() {
        return selectedMovies;
    }

    public void setSelectedMovies(TRefillingDetailsRf[] selectedMovies) {
        this.selectedMovies = selectedMovies;
    }

/*    public List<String> getMoviesByTitle(String title) {
        List<TRefillingDetailsRf> foundMovies = allotmentService.findByTitle(title);
        List<String> titles = new ArrayList<String>();

        for (TRefillingDetailsRf m : foundMovies) {
            titles.add(m.getTitle());
        }

        return titles;
    }*/

    public void search(ActionEvent actionEvent) {
    	lazyDataModel.load(0, 10, null, SortOrder.UNSORTED, new HashMap<String, String>() {
            {
                put("title", getTitle());
            }
        });
    }
}